<template>
  <view class="content">
	  <u-navbar :is-back="false" title="拜访记录"
	    title-size="30"
	    :background="{background:'#2B88FE' }"
	    title-color="#fff">
	    <div class="head_icon">
	      <u-icon @click="$api.handleBackTo"
	        name="arrow-left" color="#fff"
	        size="36">
	      </u-icon>
	      <u-icon @click="$api.handleHomeTo"
	        name="home" color="#fff" size="36">
	      </u-icon>
	    </div>
	  </u-navbar>
    <u-sticky
      style="height: 110upx;"
      bg-color="#F8F9FC">
      <view
        class="topsearch x-row fff">
        <view
          class="x-col-center x-col">
          <view
            class="search">
            <u-search
              placeholder="搜索拜访记录"
              @change="changeSearch"
              shape="square"
              bg-color="#fff"
              :show-action="false"
              height="70"
              v-model="keywords">
            </u-search>
          </view>
        </view>
      </view>
    </u-sticky>
    <order-item
      v-for="(item,index) in clist"
      :key="index" :li="item"
      @clickMsg="$api.navigator(`/pages/my_customer/my_customer_client?id=${item.fMrkId}&fTaskId=${item.fTaskId}`)">
      <view slot="detail">
        <navigator
          class="order-button"
          :url="`/pages/sale/visit_records_data?fMrkId=${item.fMrkId}&id=${item.fId}`">
          查看详情
        </navigator>
      </view>
      <view
        style="margin-top:20rpx"
        slot="footer">
        拜访时间：{{item.VisitTime}}
      </view>
    </order-item>
    <u-empty text="暂无数据"
      mode="list"
      v-if="!clist.length">
    </u-empty>
  </view>
</template>

<script>
import orderItem from '@/components/order-item'
export default {
  components: {
    orderItem
  },
  data() {
    return {
      show: false,
      keyword: '',
      img: this.urlimg + 'mini/',
      list: [
        {
          text: '客户资料'
        },
        {
          text: '商家总数据'
        },
        {
          text: '商家订单'
        }
      ],

      keywords: '',
      clist: [],
      isAllList: 1,
      page: 10,
      status: 'loading',
      loading: true,
      timeout: null,
      li: ''
    }
  },
  onShow(e) {
    this.defaultData()
    this.getList()
  },
  onReachBottom() {
    if (this.isAllList != 0) {
      this.page += 1
      this.getList()
    }
  },
  methods: {
    changeSearch() {
      if (this.timeout) clearTimeout(this.timeout)
      this.timeout = setTimeout(() => {
        this.getList()
      }, 100)
    },
    cellPhone(e) {
      uni.makePhoneCall({
        phoneNumber: e.phone
      })
    },
    toStore(e) {
      uni.openLocation({
        //​使用微信内置地图查看位置。
        latitude: parseFloat(e.lat), //要去的纬度-地址
        longitude: parseFloat(e.lon), //要去的经度-地址
        name: e.map_address
      })
    },
    gotoPage(url) {
      this.$api.navigator(url)
    },
    clickMsg(e) {
      this.li = e
      this.show = true
    },
    onSheet(e) {
      switch (e) {
        case 0:
          uni.navigateTo({
            url: 'my_customer_detail?id=' + this.li.id
          })
          break
        case 1:
          uni.navigateTo({
            url: 'my_customer_total?id=' + this.li.id
          })
          break
        case 2:
          uni.navigateTo({
            url: '../sale/order_customer?id=' + this.li.id
          })
          break
      }
    },
    fandou(fn, delay) {
      let timeout = null
      return function () {
        if (timeout) clearTimeout(timeout)
        timeout = setTimeout(() => {
          fn.apply(this, arguments)
        }, delay)
      }
    },
    defaultData(callback) {
      this.isAllList = 1
      this.page = 1
      this.clist = []
      this.status = 'loading'
      this.loading = true
      callback && callback()
    },
    getList() {
      let that = this,
        params = {
          VisitTime: 0,
          MrkId: 0,
          Key: this.keywords,
          PageIndex: this.page
        }
      this.$axios('api/UserVisit/ListPaged', 'post', params).then(res => {
        if (!res.Value.List.length) {
          this.isAllList = 0
        }
        that.loading = false
        res.Value.List.forEach(x => {
          x.fName = x.fMrkName
          x.fTell = x.fMrkTell
          x.fClassSizeName = x.fMrkSize
          x.fStreet = x.fMrkAdd
          x.fPic = x.fMrkPic
          x.fAddress = ''
          x.address = ''
        })
        that.clist.push(...res.Value.List)
      })
    }
  }
}
</script>
